package com.yanxibao.controller;

import com.yanxibao.bean.Comments;
import com.yanxibao.common.Result;
import com.yanxibao.dto.CommentsUserDTO;
import com.yanxibao.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论控制器
 *
 * @author kongke
 * @date 2023/11/19
 */
@Api(tags = "评论信息接口")
@CrossOrigin
@RequestMapping("/comments")
@RestController
public class CommentsController {

    @Resource
    private CommentsService commentsService;


    /**
     * 增加评论
     * @param comments
     * @return
     */
    @ApiOperation("添加评论")
    @PostMapping("/addComments")
    public Result<Comments> addComments(@RequestBody Comments comments){
        return commentsService.addComments(comments);
    }

    /**
     * 获取 评论
     * @param
     */
    @ApiOperation("查询评论")
    @GetMapping("/getCommentsUserList/{blogId}")
    public Result<List<CommentsUserDTO>> getCommentsList(@PathVariable Integer blogId){
        return commentsService.getCommentsList(blogId);
    }

    /**
     * 点赞
     * @param id 评论Id
     * @return {@link Result}<{@link Integer}> 最新点赞数
     */
    @ApiOperation("更新（点赞）")
    @PutMapping("/likes/{id}")
    public Result<Integer> likes(@PathVariable("id") Integer id){
        return commentsService.likes(id);
    }


    /**
     * 删除评论
     * @param id 评论Id
     */
    @ApiOperation("删除评论信息")
    @DeleteMapping("/deleteComments/{id}")
    public Result<Boolean> deleteComments(@PathVariable("id") Integer id){
        return commentsService.deleteComments(id);
    }



}
